
use "Data\MFPS Child Health Paper Replication Data - Woman Level.dta", clear


* \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 
* Table 1
* \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

* Create local of balance table variables
local womvar curr_use_bl more_eff_method_bl injectable_bl implant_bl ever_use_bl age_bl total_birth_bl edu_primary_bl secondary tertiary religion_r_bl ethnicity_r_bl work_bl sex_age_bl

*Women Baseline Balance 
iebaltab `womvar' if year ==2016 & preg_bl == 0, grpvar(treatment) total ftest pftest fmissok rowlabels(curr_use_bl "Mother's Contraceptive Use"   @ ///
				 injectable_bl "Injectable use"   @ ///
				 implant_bl "Implant use"   @ ///
				 ever_use_bl  "Ever Use of Contraceptive"  @     ///
				 edu_primary_bl  "Mother has primary Education" @ ///
				 secondary "Mother has secondary education"   @ ///
				 tertiary "Mother has tertiary education"   @ ///
				 work_bl  "Mother works" @ ///
				 sex_age_bl  "Mother's age of Sexual Debut" @ ///
				 total_birth_bl "Number of Births to Mother" @ ///
				 age_bl "Mother's Age" @ ///
				 religion_r_bl "Mother's Religion" @ ///
				 ethnicity_r_bl "Mother's Ethnicity") ///
save("Results\Balance Tables\Mother Baseline Balance.xlsx") replace

* Pull in Data
use "Data\MFPS Child Health Paper Replication Data - Child Level.dta", clear

* Create local of balance table variables
local chivar child_age_months child_sex birth_order 
local measurevar pre_interval_bl haz06_bl whz06_bl waz06_bl

*Child Baseline Balance 
iebaltab `chivar' `measurevar' if year ==2016 & index_dummy==1 & born_during_study==0, grpvar(treatment) total ftest pftest fmissok rowlabels(child_age_months "Child's age (months)" @ ///
				 child_sex "Child Biological Sex" @ ///
				 birth_order "Child's Birth Order" @ ///
				 pre_interval_bl "Preceeding Birth Interval" @ ///
				 haz06_bl "Height for age Z-Score" @ ///
				 whz06_bl "Weight for age Z-score") ///
save("Results\Balance Tables\Child Baseline Balance.xlsx") replace


* /////////////////////////////////////////////////////////////////////////////
* Table 5
* /////////////////////////////////////////////////////////////////////////////

* Child Attrition Balance for 2017
replace haz_missing = 1 if haz_missing == . & year ==2016
gen attrition_group_2017 = 0 
replace attrition_group_2017 = 1 if haz_missing==0 & treatment ==1 
replace attrition_group_2017 = 2 if haz_missing==0 & treatment ==0
replace attrition_group_2017 = 3 if haz_missing==1 & treatment ==1 
replace attrition_group_2017 = 4 if haz_missing==1 & treatment ==0
iebaltab `womvar' `chivar' if year ==2016 & index_dummy==1 & born_during_study==0, grpvar(attrition_group_2017) total ftest pftest fmissok rowlabels(curr_use_bl "Mother's Contraceptive Use"   @ ///
				 injectable_bl "Injectable use"   @ ///
				 implant_bl "Implant use"   @ ///
				 ever_use_bl  "Ever Use of Contraceptive"  @     ///
				 edu_primary_bl  "Mother has primary Education" @ ///
				 secondary "Mother has secondary education"   @ ///
				 tertiary "Mother has tertiary education"   @ ///
				 work_bl  "Mother works" @ ///
				 sex_age_bl  "Mother's age of Sexual Debut" @ ///
				 total_birth_bl "Number of Births to Mother" @ ///
				 age_bl "Mother's Age" @ ///
				 religion_r_bl "Mother's Religion" @ ///
				 ethnicity_r_bl "Mother's Ethnicity" @ ///
				 child_age_months "Child's age (months)" @ ///
				 child_sex "Child Biological Sex" @ ///
				 birth_order "Child's Birth Order") ///
grplabels("1 treatment/followed @ 2 control/followed @ 3 treatment/Attrit @ 4 control/Attrit") ///
save("Results\Balance Tables\FUP1 Attrition Balance.xlsx") replace

/////////////////////////////////////////////////////////////////////////////
* Table A1: Maternal Characteristics by Birth Spacing
/////////////////////////////////////////////////////////////////////////////
use "Data\MFPS Child Health Paper Replication Data - Woman Level.dta", clear
* Create local of balance table variables
local womvar curr_use_bl more_eff_method_bl injectable_bl implant_bl ever_use_bl age_bl total_birth_bl edu_primary_bl secondary tertiary religion_r_bl ethnicity_r_bl work_bl sex_age_bl

*Women Baseline Balance 
iebaltab `womvar' if year ==2018, grpvar(next_preg_2018) total ftest pftest fmissok rowlabels(curr_use_bl "Mother's Contraceptive Use"   @ ///
				 injectable_bl "Injectable use"   @ ///
				 implant_bl "Implant use"   @ ///
				 ever_use_bl  "Ever Use of Contraceptive"  @     ///
				 edu_primary_bl  "Mother has primary Education" @ ///
				 secondary "Mother has secondary education"   @ ///
				 tertiary "Mother has tertiary education"   @ ///
				 work_bl  "Mother works" @ ///
				 sex_age_bl  "Mother's age of Sexual Debut" @ ///
				 total_birth_bl "Number of Births to Mother" @ ///
				 age_bl "Mother's Age" @ ///
				 religion_r_bl "Mother's Religion" @ ///
				 ethnicity_r_bl "Mother's Ethnicity") ///
save("Results\Balance Tables\Birth Spacing Maternal Balance.xlsx") replace


* \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 
* Table B1
* \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

tabstat important_feat_1 important_feat_2 important_feat_3 important_feat_4 important_feat_5 important_feat_6 important_feat_7 important_feat_8 important_feat_9, statistic(mean) columns(statistics)

* \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 
* Table B2
* \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

* Create local of balance table variables
local womvar wantanother wait_length fert_pref total_birth_bl probpreg_bl

*Women Baseline Balance 
iebaltab `womvar' if year ==2016 & preg_bl ==0, grpvar(curr_use_bl) total rowlabels(wantanother "Want's Another Child"   @ ///
				 wait_length "Desired Wait Time Until Next Child"   @ ///
				 fert_pref "Desired Number of Children"   @ ///
				 total_birth_bl  "Number of Births"  @     ///
				 probpreg_bl  "Percieved Probability of Pregnancy") ///	 
save("Results\Balance Tables\Contraceptive Balance Table.xlsx") replace

* Test Difference in variance across pregnancy probability
foreach i of local womvar{
	sdtest `i' if year==2016 & preg_bl==0, by(curr_use_bl)
}




